<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>
    <button class="btn1">发送请求11</button>

    <script>
        // axios里的配置项 
        /* 
            axios({
                配置项
            })
            axios.get(url,{配置项})
            axios.post(url,{data},{配置项});

        
        
        */
        document.querySelector(".btn1").onclick = function () {
            axios({
                url: "/getdata",
                hello: "123",
                params: { x: 1, y: 2 },
                data: {
                    a: 1,
                    b: 2
                },
                transformRequest: [function (data, headers) {
                    // 对发送的 data 进行任意转换处理
                    console.log(data);
                    return data;
                }],
                headers:{
                    myheader:"value",
                    myheader2:"values"
                },
                transformResponse: [function (data) {
                    // 对接收的 data 进行任意转换处理
                    console.log("返还的结果",data);

                    return JSON.parse( data);
                }]
            }).then(res => {
                console.log(res);
            })
        }
    </script>
</body>

</html>